package com.springclouddemo.common.view;

import java.util.Map;

public class PagerParam {
    /**
     * 页码(page,pageindex,pageIndex)
     * @param params
     * @return
     */
    public static long getPage(Map<String, Object> params){
        long l = getLong(params,"page");
        if(l<=0){
            l = getLong(params,"pageindex");
        }
        if(l<=0){
            l = getLong(params,"pageIndex");
        }
        if(l<=0){
            l=1;
        }
        return l;
    }

    /**
     * 数量(limit,pagesize,pageSize)
     * @param params
     * @return
     */
    public static long getLimit(Map<String, Object> params){
        long l = getLong(params,"limit");
        if(l<=0){
            l = getLong(params,"pagesize");
        }
        if(l<=0){
            l = getLong(params,"pageSize");
        }
        if(l<=0){
            l=10;
        }
        return l;
    }

    public static long  getLong(Map<String, Object> params,String key){
        long l=0;
        if(params.get(key)!=null){
            l = Long.valueOf(params.get(key).toString());
        }
        return l;
    }
}
